use crate::server::ServerConfig;
use config_plus::Configuration;
use serde::Deserialize;

/// 配置类
#[derive(Deserialize, Configuration)]
#[config(file(path = "application.toml"), env(name = "AXUM_CONFIG_PATH"))]
#[serde(rename_all(deserialize = "kebab-case"))]
struct Configuration {
    #[serde(default)]
    server: ServerConfig,
    #[cfg(feature = "auth")]
    #[serde(default)]
    auth: crate::middleware::AuthConfig,
    #[cfg(feature = "database")]
    #[serde(default)]
    database: crate::db::DatabaseConfig,
    #[cfg(feature = "redis")]
    #[serde(default)]
    redis: crate::rediss::RedisConfig,
    #[cfg(feature = "amqp")]
    #[serde(default)]
    amqp: crate::amqp::AmqpConfig,
    #[cfg(feature = "email")]
    email: crate::email::EmailConfig,
    #[cfg(feature = "minio")]
    #[serde(default)]
    minio: crate::minio::MinioConfig,
}

/// 获取`server`配置
pub fn server() -> &'static ServerConfig {
    &Configuration::config().server
}

/// 获取`auth`配置
#[cfg(feature = "auth")]
pub fn auth() -> &'static crate::middleware::AuthConfig {
    &Configuration::config().auth
}

/// 获取`database`配置
#[cfg(feature = "database")]
pub fn database() -> &'static crate::db::DatabaseConfig {
    &Configuration::config().database
}

/// 获取`redis`配置
#[cfg(feature = "redis")]
pub fn redis() -> &'static crate::rediss::RedisConfig {
    &Configuration::config().redis
}


/// 获取`amqp`配置
#[cfg(feature = "amqp")]
pub fn amqp() -> &'static crate::amqp::AmqpConfig {
    &Configuration::config().amqp
}

/// 获取`email`配置
#[cfg(feature = "email")]
pub fn email() -> &'static crate::email::EmailConfig {
    &Configuration::config().email
}

/// 获取`minio`配置
#[cfg(feature = "minio")]
pub fn minio() -> &'static crate::minio::MinioConfig {
    &Configuration::config().minio
}